#include <iostream>
using namespace std;

#include <vector>
#include <set>

class Solution
{
    vector<vector<int>> ret;
    vector<int> path;
    set<vector<int>> s;
    bool check[9];
public:
    vector<vector<int>> permuteUnique(vector<int>& nums)
    {
        dfs(nums);
        for (auto& e : s)
        {
            ret.push_back(e);
        }
        return ret;
    }

    void dfs(vector<int>& nums)
    {
        if (path.size() == nums.size())
        {
            s.insert(path);
            return;
        }

        for (int i = 0; i < nums.size(); i++)
        {
            if (check[i] == false)
            {
                path.push_back(nums[i]);
                check[i] = true;
                dfs(nums);
                path.pop_back();
                check[i] = false;
            }
        }
    }
};

int main()
{
    Solution s;
    vector<int> nums = { 1,2,3};
    auto ret = s.permuteUnique(nums);

    return 0;
}